import { ApiProperty } from '@nestjs/swagger';
import { IsOptional, IsString, IsNumber, Min, Matches } from 'class-validator';
import { Type } from 'class-transformer';

export class VisitorStatsDto {
  @ApiProperty({ example: 12345, description: '总访客数' })
  totalVisitors: number;

  @ApiProperty({ example: 234, description: '今日访客数' })
  todayVisitors: number;

  @ApiProperty({ example: 3.5, description: '平均停留时间（分钟）' })
  averageDuration: number;

  @ApiProperty({ example: 45, description: '当前在线人数' })
  onlineUsers: number;
}

export class VisitorTrendDto {
  @ApiProperty({ example: '2024-03-20', description: '日期' })
  date: string;

  @ApiProperty({ example: 234, description: '访客数量' })
  count: number;
}

export class VisitorSourceDto {
  @ApiProperty({ example: '直接访问', description: '来源类型' })
  source: string;

  @ApiProperty({ example: 123, description: '访客数量' })
  count: number;
}

export class VisitorRecordDto {
  @ApiProperty({ example: '2024-03-20 14:30:00', description: '访问时间' })
  visitTime: Date;

  @ApiProperty({ example: '192.168.1.1', description: 'IP地址' })
  ip: string;

  @ApiProperty({ example: '中国 北京', description: '地理位置' })
  location: string;

  @ApiProperty({ example: 'Chrome/Windows', description: '设备信息' })
  device: string;

  @ApiProperty({ example: '直接访问', description: '来源' })
  source: string;
}

export class VisitorQueryDto {
  @ApiProperty({ required: false, description: '开始日期 (YYYY-MM-DD)', example: '2024-03-01' })
  @IsOptional()
  @IsString()
  @Matches(/^\d{4}-\d{2}-\d{2}$/, { message: '日期格式必须为 YYYY-MM-DD' })
  startDate?: string;

  @ApiProperty({ required: false, description: '结束日期 (YYYY-MM-DD)', example: '2024-03-20' })
  @IsOptional()
  @IsString()
  @Matches(/^\d{4}-\d{2}-\d{2}$/, { message: '日期格式必须为 YYYY-MM-DD' })
  endDate?: string;

  @ApiProperty({ required: false, description: '页码', default: 1, minimum: 1 })
  @IsOptional()
  @Type(() => Number)
  @IsNumber()
  @Min(1)
  page?: number = 1;

  @ApiProperty({ required: false, description: '每页数量', default: 10, minimum: 1 })
  @IsOptional()
  @Type(() => Number)
  @IsNumber()
  @Min(1)
  limit?: number = 10;
} 